#include <iostream>
//复杂产品
class Car
{
    public:
    void setEngine(std::string engine)
    {
        this->engine = engine;
    }

    void setWheel(std::string wheel)
    {
        this->wheel = wheel;
    }

    void setBody(std::string body)
    {
        this->body = body;
    }

    void show()
    {
        std::cout<<"建好了一辆汽车:"<<engine<<","<<wheel<<","<<body<<std::endl;
    }
private:
    std::string engine;//引擎
    std::string wheel;//轮胎
    std::string body;//车身
};

//建造者抽象类
class Assemble
{
public:
    Assemble():c (new Car){}
    virtual void AssembleEngine() = 0;
    virtual void AssembleWheel() = 0;
    virtual void AssembleBody() = 0;
    virtual Car* GetCar()
    {
        return c;
    }
protected:
    Car* c;
};

//具体建造者
class AssembleA:public Assemble
{
public:
    void AssembleEngine()
    {
        c->setEngine("引擎A");
    }
    void AssembleWheel()
    {
        c->setWheel("轮胎A");
    }
      void AssembleBody()
    {
        c->setBody("车身A");
    }
};

class AssembleB:public Assemble
{
public:
    void AssembleEngine()
    {
        c->setEngine("引擎B");
    }
    void AssembleWheel()
    {
        c->setWheel("轮胎B");
    }
      void AssembleBody()
    {
        c->setBody("车身B");
    }
};

//指挥者
class Director
{
    public:
    Director(Assemble *a)
    {
        this->a = a;
    }
    Car* AssembleCar()
    {
        a->AssembleBody();
        a->AssembleEngine();
        a->AssembleWheel();
        return a->GetCar();
    }
private:
Assemble *a;
};

int main()
{
    //定义建造者类型
    Assemble *a = new AssembleA;
    //把建造者给指挥者
    Director *d = new Director(a);
    d->AssembleCar()->show();
    return 0;
}